package com.abl.common.mybatis;

import com.abl.common.mybatis.strengthen.DbFillImpl;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus功能配置
 *
 * @author WangYongJi
 * <p>
 * 1.分页配置
 * 2.驼峰转换
 */
@Slf4j
@Configuration
public class MybatisConfig {

    /**
     * 1.分页配置
     */
    @Bean
    public PaginationInnerInterceptor paginationInterceptor() {
        PaginationInnerInterceptor page = new PaginationInnerInterceptor();
        page.setDbType(DbType.MYSQL);
        return page;
    }


    /**
     * 3.默认注入
     */
    @Bean
    public DbFillImpl dbFileHandler() {
        return new DbFillImpl();
    }


// 2.驼峰转换+
//    @Bean
//    public ConfigurationCustomizer configurationCustomizer() {
//        return configuration -> configuration.setObjectWrapperFactory(new WrapperFactory());
//    }
    //驼峰转换
//    static class WrapperFactory implements ObjectWrapperFactory {
//        @Override
//        public boolean hasWrapperFor(Object o) {
//            return o instanceof Map;
//        }
//
//        @Override
//        public ObjectWrapper getWrapperFor(MetaObject metaObject, Object o) {
//            return new MiMapWrapper(metaObject, (Map) o);
//        }
//
//        static class MiMapWrapper extends MapWrapper {
//            MiMapWrapper(MetaObject metaObject, Map<String, Object> map) {
//                super(metaObject, map);
//            }
//
//            @Override
//            public String findProperty(String name, boolean useCamelCaseMapping) {
//                if (useCamelCaseMapping) return HumpKit._ToHump(name);
//                return name;
//            }
//        }
//    }

}
